package com.xbongbong.pro.statistic.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.enums.clazz.AggsTypeClass;
import lombok.Getter;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

/**
 * 省市区类型
 *
 * @author zcp
 * @version v1.0
 * @date 2019/1/11
 * @since v1.0
 */
@Getter
public enum AreaTypeEnum {

    CHINA(0,"enum.areaType.name.china","china"),

    PROVINCE(1,"enum.areaType.name.province","province"),

    CITY(2,"enum.areaType.name.city","city"),

    DISTRICT(3,"enum.areaType.name.district","district"),
    ;

    /**
     * code值
     */
    private int code;
    /**
     * 类型名
     */
    private String name;

    private String alias;


    AreaTypeEnum(int code, String name,String alias) {
        this.code = code;
        this.name = name;
        this.alias = alias;
    }


    /**
     * 根据code值获取枚举
     * @param code
     * @return
     */
    public static AreaTypeEnum getByCode(Integer code) {
        for (AreaTypeEnum cacheCode : values()) {
            if (Objects.equals(cacheCode.code,code)) {
                return cacheCode;
            }
        }
        return null;
    }

    public static AreaTypeEnum getByAlias(String alias) {
        for (AreaTypeEnum cacheCode : values()) {
            if (Objects.equals(cacheCode.getAlias(), alias)) {
                return cacheCode;
            }
        }
        return null;
    }


    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }

    public static boolean isAddRange(String alias){
        List<String> list = Arrays.asList(PROVINCE.getAlias(),CITY.getAlias(),DISTRICT.getAlias());
        return null != alias && list.contains(alias);
    }
}
